"""
操作mongo
"""
import pymongo

# 远程连接
# client = pymongo.MongoClient('mongodb://192.168.231.133:27017')
client = pymongo.MongoClient(host='192.168.231.133', port=27017)
print(client)
# 创建数据库对象
db = client['db_qk']
print(db)
# 创建表对象
tb = db['tb_stu']
# 插入数据
# tb.insert_one({'name': 'zhangsan', 'age': 20})
# tb.insert_one({'name': 'zhangsan', 'age': 21})
# tb.insert_one({'name': 'zhangsan', 'age': 22})
# tb.insert_one({'name': 'zhangsan', 'age': 23})
# 删除数据
dl = tb.delete_one({'age': 20})
print(dl)
# 查询数据
datas = tb.find()
print(datas)
# 遍历数据
for data in datas:
    print(data)
# 关闭连接  释放资源
client.close()
